<?php
namespace app\home\controller;

use alipay\Wappay;
use app\admin\model\Config;
use app\admin\model\Message;
use app\common\controller\Basehome;
use app\admin\model\Article as Articlemodel;
use think\Request;

class Index  extends Basehome
{

    protected $Articlemodel;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->Articlemodel=new Articlemodel();
    }

    /**
     * wap支付
     */
    public function index()
    {
        $Wappay=new  Wappay();

        $param=[
            'subject'=>'西红柿',
            'out_trade_no'=>time(),
            'total_amount'=>100.,
        ];
        echo  $Wappay::pay($param);
    }
    public function about(){
        return $this->fetch();
    }
    public function service(){
        $list=$this->Articlemodel->getlistrelation('',5,3);
        $list=collection($list)->toArray();
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function news(){
        $list = $this->Articlemodel->where(['status'=>1,'column_id'=>4])->order('id desc')->paginate(3);
        $page = $list->render();
        $this->assign('listinfo', $list);
        $this->assign('page', $page);
        return $this->fetch();
    }
    public function links(){
        return $this->fetch();
    }
    public function addmessage(){
        $Message=new Message();
        $data =$this->request->param();
        $validate=validate('Message');
        if(!$validate->check($data)){
            return json(['msg'=>$validate->getError()]);
        }
        $res=$Message->allowField(true)->save($data);
        if($res){
            return json(['msg'=>'添加成功！','status'=>1]);
        }else{
            return json(['msg'=>'添加失败，请稍后再尝试！']);
        }
    }
}
